package com.easylinkin.linkappapi.lobar.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.lobar.entity.LaborCompany;
import com.easylinkin.linkappapi.lobar.service.LaborCompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2020/11/04 11:42
 * @Description: 项目劳务公司管理
 */
@RestController
@RequestMapping("laborCompany")
@Api(tags = "项目劳务公司管理")
public class LaborCompanyController {
  
  @Autowired
  private LaborCompanyService laborCompanyService;

  /**
   * @Description: 增加劳务公司
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping
  @ApiOperation("增加劳务公司")
  public RestMessage insert(@RequestBody LaborCompany laborCompany){
    //todo 参数验证
    laborCompanyService.insert(laborCompany);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 删除劳务公司（包含批量删除）
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @DeleteMapping
  @ApiOperation("删除劳务公司（包含批量删除）")
  public RestMessage delBatch(@RequestBody LaborCompany laborCompany){
    Assert.notEmpty(laborCompany.getIds(),"id不能为空");
    laborCompanyService.removeByIds(laborCompany.getIds());
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 编辑劳务公司
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PutMapping
  @ApiOperation("编辑劳务公司")
  public RestMessage updateById(@RequestBody LaborCompany laborCompany){
    Assert.notNull(laborCompany.getId(),"id不能为空");
    laborCompanyService.updateOne(laborCompany);
    return RestBuilders.successBuilder().build();
  }

  /**
   * @Description: 根据id查询劳务公司详情
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @GetMapping("{id}")
  @ApiOperation("根据id查询劳务公司详情")
  public RestMessage findById(@PathVariable("id")String id) {
    Assert.notNull(id,"id不能为空");
    LaborCompany laborCompany = laborCompanyService.getById(id);
    return RestBuilders.successBuilder().data(laborCompany).build();
  }

  /**
   * @Description: 根据code查询劳务公司详情
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @GetMapping("code/{code}")
  @ApiOperation("根据id查询劳务公司详情")
  public RestMessage findByCode(@PathVariable("code")String code) {
    Assert.notNull(code,"code不能为空");
    LaborCompany laborCompany = laborCompanyService.findByCode(code);
    return RestBuilders.successBuilder().data(laborCompany).build();
  }

  /**
   * @Description: 根据条件，分页(不分页)查询
   * @author kan yuanfeng
   * @date 2020/11/04 11:42
   */
  @PostMapping("list")
  @ApiOperation("根据条件，分页(不分页)查询")
  public RestMessage queryListByPage(@RequestBody RequestModel<LaborCompany> requestModel){
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<LaborCompany> record =  laborCompanyService.queryListByPage(requestModel);
    return RestBuilders.successBuilder().data(record).build();
  }
}

